package cn.com.egova.erp.biz.impl;

import cn.com.egova.erp.biz.IReportBiz;
import cn.com.egova.erp.dao.IReportDao;

import java.util.*;

/**
 * Created by yuanchao on 2020/6/9.
 */
public class ReportBiz implements IReportBiz {
    private IReportDao reportDao;

    public void setReportDao(IReportDao reportDao) {
        this.reportDao = reportDao;
    }

    @Override
    public List<Map<String, Object>> ordersReport(Date startDate, Date endDate) {
        return reportDao.ordersReport(startDate, endDate);
    }

    @Override
    public List<Map<String, Object>> getSumMoney(int year) {
        //对月份数据查漏补缺
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String, Object> dateMoney = null;
        for (int i = 1; i <= 12; i++) {
            dateMoney = new HashMap<>();
            dateMoney.put("month", i + "月");
            dateMoney.put("money", 0);
            resultList.add(dateMoney);
        }
        //查询实际数据
        List<Map<String, Object>> mapList = reportDao.getSumMoney(year);
        //替换
        if (mapList != null && mapList.size() > 0) {
            for (Map<String, Object> map : mapList) {
                for (Map<String, Object> resultMap : resultList) {
                    if (map.get("month").equals(resultMap.get("month"))) {
                        resultMap.put("money", map.get("money"));
                        continue;
                    }
                }
            }
        }
        return resultList;
    }
}
